package com.didispace.chapter56.service.impl;

import com.didispace.chapter56.domain.Role;
import com.didispace.chapter56.repository.RoleRepository;
import com.didispace.chapter56.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
@Transactional
public class RoleServiceImpl implements RoleService {

    private RoleRepository repository;

    @Autowired
    public void setRepository(RoleRepository repository) {
        this.repository = repository;
    }

    @Override
    public Role selectByRoleId(Long id) {
        Optional<Role> roleOptional = this.repository.findById(id);
        if (roleOptional.isPresent()) {
            return roleOptional.get();
        }
        return null;
    }
}
